package com.mathdroid.model;

import java.io.Serializable;

import com.mathdroid.model.abilities.AbilityFactory;
import com.mathdroid.model.abilities.AbilityTemplate;
import com.mathdroid.model.buffs.BuffFactory;
import com.mathdroid.model.buffs.BuffTemplate;
import com.mathdroid.model.encounters.EncounterFactory;
import com.mathdroid.model.encounters.EncounterTemplate;
import com.mathdroid.model.enums.EItemSlot;
import com.mathdroid.model.enums.ESpec;
import com.mathdroid.model.items.EquipedItems;
import com.mathdroid.model.items.ItemBrowserModel;
import com.mathdroid.model.items.ItemTemplates;
import com.mathdroid.model.stats.BaseStatsFactory;
import com.mathdroid.model.talents.Spec;
import com.mathdroid.model.talents.SpecFactory;
import com.mathdroid.modules.ClassModuleFactory;

/**
 * This is a profile that contains all character settings and used templates.
 */
public final class Profile implements Serializable {
	/**
	 * Generated UID.
	 */
	private static final long serialVersionUID = 973209130887344590L;

	/**
	 * The specialization of this character.
	 */
	private ESpec spec = ESpec.SNIPER;
	
	/**
	 * The name of the character/profile.
	 */
	private String name = "Unknown";
	
	/**
	 * The spec template used in this profile.
	 */
	private Spec specTemplate = SpecFactory.getTalents(this.spec);
	
	/**
	 * The current encounter settings.
	 */
	private EncounterTemplate encounter = EncounterFactory
						.getDefaultTemplates().get(EncounterFactory.DEFAULT);
	
	/**
	 * The current ability settings.
	 */
	private AbilityTemplate abilities = new AbilityFactory().get(this.spec);
	
	/**
	 * The buff template used in this profile.
	 */
	private BuffTemplate buffTemplate = 
		BuffFactory.getNewUnbuffedTemplate();
	
	/**
	 * The item templates for this character profile.
	 */
	private ItemTemplates itemTemplates = new ItemTemplates();
	
	/**
	 * The equiped items.
	 */
	private EquipedItems equipedItems = new EquipedItems();
	
	/**
	 * The class module for this specialization.
	 */
	private ClassModuleFactory classModule = new ClassModuleFactory();

	/**
	 * The current item browser model.
	 */
	private ItemBrowserModel itemBrowserModel = 
		new ItemBrowserModel(EItemSlot.HEAD.toString());

	/**
	 * The current base stats.
	 */
	private Stats baseStats = new BaseStatsFactory().get(this.spec);
	
	/**
	 * Create a new profile.
	 * @param n Name.
	 * @param s Specialization.
	 */
	public Profile(final String n, final ESpec s) {
		this.name = n;
		this.spec = s;
	}

	/**
	 * Get the character specialization.
	 * @return Character specialization.
	 */
	public ESpec getSpec() {
		return this.spec;
	}
	
	/**
	 * Set the character specialization.
	 * @param s Character specialization.
	 */
	public void setSpec(final ESpec s) {
		this.spec = s;
	}

	/**
	 * Get the name of the character/profile.
	 * @return Name of character/profile.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Set the character/profile name.
	 * @param n Character/profile name.
	 */
	public void setName(final String n) {
		this.name = n;
	}
	
	/**
	 * Set the spec template of this profile.
	 * @param s Spec template.
	 */
	public void setSpecTemplate(final Spec s) {
		this.specTemplate = s;
	}
	
	/**
	 * Get the spec template of this profile.
	 * @return Spec template.
	 */
	public Spec getSpecTemplate() {
		return this.specTemplate;
	}
	
	/**
	 * Get the buff template of this profile.	
	 * @return Buff template.
	 */
	public BuffTemplate getBuffTemplate() {
		return buffTemplate;
	}

	/**
	 * Set the buff template of this profile.
	 * @param t Buff template.
	 */
	public void setBuffTemplate(final BuffTemplate t) {
		this.buffTemplate = t;
	}
	
	/**
	 * Get the encounter template of this profile.
	 * @return Encounter Profile.
	 */
	public EncounterTemplate getEncounter() {
		return encounter;
	}

	/**
	 * Set this profiles encounter template.
	 * @param e Encounter template.
	 */
	public void setEncounter(final EncounterTemplate e) {
		this.encounter = e;
	}

	/**
	 * Get the item templates for this character profile.
	 * @return Item templates.
	 */
	public ItemTemplates getItemTemplates() {
		return itemTemplates;
	}

	/**
	 * Get the equiped item set.
	 * @return Equiped items.
	 */
	public EquipedItems getEquipedItems() {
		return equipedItems;
	}

	@Override
	public String toString() {
		return this.name;
	}

	/**
	 * Set the equipped items.
	 * @param t Equipped items.
	 */
	public void setEquipedItems(final EquipedItems t) {
		this.equipedItems = t;		
	}

	/**
	 * Get the logic for this specialization.
	 * @return Spec logic.
	 */
	public ClassModuleFactory getClassModule() {
		return this.classModule;
	}
	
	/**
	 * Set the class module.
	 * @param c ClassModule.
	 */
	public void setClassModule(final ClassModuleFactory c) {
		this.classModule = c;
	}

	/**
	 * Get the item browser model.
	 * @return Item browser model.
	 */
	public ItemBrowserModel getItemBrowserModel() {
		return this.itemBrowserModel;
	}
	
	/**
	 * Get the current abilities.
	 * @return Current Abilities.
	 */
	public AbilityTemplate getAbilities() {
		return this.abilities;
	}
	
	/**
	 * Set the current abilities.
	 * @param t Current Abilities.
	 */
	public void setAbilities(final AbilityTemplate t) {
		this.abilities = t;
	}

	/**
	 * Get the base stats of the current specialization.
	 * @return Current base stats.
	 */
	public Stats getBaseStats() {
		return this.baseStats;
	}
}
